<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../layui/css/layui.css">
  <title>Document</title>
</head>

<body>
  <%- include('head',{title:'album',username:username })%>
    <h2>
      <%- username %>
    </h2>
    <button class="album-add-btn">添加相册</button>
    <% result.forEach((item,idx)=>{ %>
      <div class="item-box">
        <div><a href="/picture?aid=<%- item._id %>">相册图标</a></div>
        <div>相册名 <%- item.albumname %>
        </div>
        <div>创建时间：<%- item.time %>
        </div>
      </div>
      <% }) %>
</body>
<script src="http://47.104.209.44/base/js/jquery-1.10.1.min.js"></script>
<script src="../layui/layui.all.js"></script>

<script>
  $(document).on('click', '.album-add-btn', function () {
    //弹出选择地址框
    layer.open({
      btn: ['新建', '取消'], //按钮
      type: 1,
      title: false,
      closeBtn: 0,
      shadeClose: true,
      yes: function (index) {
        if ($('.albumname').val()) {
          console.log($('.albumname').val()); //--------
          $.ajax({
            url: "/addalbum",
            type: "post",
            data: {
              albumname: $('.albumname').val(),
            },
            success: res => {
              layer.close(index);
              alert(res.msg);
              if (res.type) {
                window.location.reload();
              }
            }
          })
        }
      },
      content: `
          <div class="album-name">
            <h4>新建相册</h4>
            <p>
              <input class="albumname" placeholder="请命名相册" type="text">
            </p>
          </div>
        `
    });
  })

</script>

</html>